/**
 * @ author: 汪孟苹
 */
define(["jquery","bbcare","comm/datatable/datatable"],function($,$bb,$datatable){
	var servers = {};
	var URL = $bb.baseUrl("followapp");
    
    /**
     * 入参
     */
    var inParams = function(args){
        var params = $bb.getPageParams();
        var data = JSON.stringify({
            data: {
                "args": JSON.stringify(args),
                "flag":"5",
                "queueId":params.queueId,
                "hisNo": $.trim($('#hisNo').val()),
                "userName": $.trim($('#userName').val()),
                "phoneNo": $.trim($('#phoneNo').val()),
                "caseStatus":$("#caseStatus").val(),
                "lastVisitTimeStart":$("#lastVisitTimeStart").val(),
                "lastVisitTimeEnd":$("#lastVisitTimeEnd").val(),
                "visitCnt":$.trim($("#visitCnt").val()),
                "visitHospital":$.trim($("#visitHospital").val()),
                "hospital":$.trim($("#hospital").val()),
                "firstVisitTimeStart":$("#firstVisitTimeStart").val(),
                "firstVisitTimeEnd":$("#firstVisitTimeEnd").val(),
            }
        });
        return data;
    }
    /**
     * 出参
     */
    var outParams = function(data){
        var params = $bb.getPageParams();
        if(params.title) $("#lapseToListTit").html(params.title);
        return data.rows;
    }
    /**
     * columns
     */
    var columnsStatus = function(e){
        switch(e.status){
            case "1":
                return "康复";
            case "2":
                return "加重";
            case "3":
                return "死亡";
            case "4":
                return "失访";
            case "5":
                return "治疗中";
            case "6":
                return "好转";
        }
    }
    var columnsData = function(){
        var columnsArr = [
            {"data":'hisNo'},
            {"data":'userName'},
            {"data":'firstVisitTime'},
            {"data":'visitCnt'},
            {"data":'hospital'},
            {"data":columnsStatus},
            {"data":'phoneNo'},
            {
                "data":null,
                "className":"operate"
            }
        ];
        return columnsArr;
    }
    /**
     * 行绘制回调函数
     */
    var rowCallback = function(row, data, index) {
        var h = data && data.status && data.status == "1" ? "-":'<div class="color-blue cursor-pointer">转归</div>';
        $('td.operate', row).html(h);
        $("td.operate .color-blue",row).unbind("click");
        $("td.operate .color-blue",row).click(function(){
            var params = $bb.getPageParams();
            $.extend(data,{"schemeId":params.schemeId,"title":params.title});
            $bb.open(params,"lapseToBth","bch_lapseToDetail",data); // "lapseToBth"对应配置表里的按钮id
        });
    };
    /**
     * 初始化完成之后的回调函数
     */
    var initComplete = function(setting,json){
        var id = $(".layout-bottom table").attr("id");
        $("#" + id).prev("div.row").remove();
        // 搜索 
        $("#serchBtn").click(function(){
            $datatable.table.api().ajax.reload();  // 出发dt的重新加载数据的方法
            var args = $datatable.table.api().ajax.params();   //获取dt请求参数 
        });
        // 初始化所有工具提示
        $(function(){$("[data-toggle='tooltip']").tooltip();});
    }
    /**
     * 获取datatable里的options
     */
    servers.getOptions = function(){
        var sessionId = $bb.getSessionStorage("sessionId");
        var options = {
            "ajax": {
                "url": URL + "ctrl/ptmanage/qryUserListTable?sessionId=" + sessionId,
                "data": inParams,
                "dataSrc": outParams
            },
            "columns": columnsData(),
            "rowCallback": rowCallback,
            "initComplete": initComplete,
        };
        return options;
    }

	return servers;
});